package com.example.wxtest.util;

import lombok.Data;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

@Data
public class Base64Encode {
    //    base64编码
    public static final String enCode(String url) throws UnsupportedEncodingException {
        System.out.println("编码===================");
        System.out.println(url);
        String encodedText = URLEncoder.encode( url, "UTF-8" );
        System.out.println("编码后===================");
        System.out.println(encodedText);
        return encodedText;
    }

    //    base64解码
    public static final String deCode(String url) throws IOException {
        System.out.println("解码前==========================");
        System.out.println(url);
        String decode = URLDecoder.decode(url, "UTF-8");
        System.out.println("解码后==========================");
        System.out.println(decode);
        return decode;
    }

    public static void main(String[] args) throws IOException {
        Base64Encode.deCode("https%3A%2F%2Fysltbon6xcwoshsh3.neiwangyun.net%2Findex.html");
        Base64Encode.enCode("https://ysltbon6xcwoshsh3.neiwangyun.net/index.html");
    }
}
